<template>
  <el-dialog :title="caption + '（' + userName +'）'" :visible.sync="visible"
             :close-on-click-modal="false">
    <el-form ref="form" label-width="10px" align="left">
      <el-form-item>
        <el-table :data="sheet.rows" highlight-current-row v-loading="sheet.loading" stripe="stripe" border="border"
                  style="width: 100%;" max-height="690">
          <el-table-column
            prop="checked" label="选中"
            width="55">

            <template slot-scope="scope">
              <el-checkbox v-model="scope.row.checked" @change="checkClick(scope.row)"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column prop="name" label="资源名称" min-width="150" :show-overflow-tooltip="true"
                           header-align="center"/>
          <el-table-column prop="remark" label="备注" min-width="150" :show-overflow-tooltip="true"
                           header-align="center"/>
        </el-table>
        <lsz-pagination :getList="getList" :sheet="sheet"/>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>
<script>
  import LszPagination from '@/components/common/lsz-pagination.vue';

  let data = () => {
    return {
      visible: false,
      sheet: {
        rows: [],
        total: 0,
        pageNum: 1,
        pageSize: 20,
        sort: 'createTime',
        loading: false,

      },
      uid: '',
      userName: ''
    }
  }
  let getList = function () {
    let url = '/resourceInfoController/getResourceInfoList';
    let filters = {
      joinTableId:this.uid
    }
    let param = {
      pageNum: this.sheet.pageNum,
      pageSize: this.sheet.pageSize,
      sort: this.sheet.sort,
      order: this.sheet.order,
      query: filters
    }
    this.sheet.loading = true
    this.$http.post(url, param).then(res => {
      let response = res.data.data;
      this.sheet.total = response.total
      this.sheet.rows = response.content
      this.sheet.loading = false

    }).catch(() => this.sheet.loading = false)
  }

  export default {
    components: {
      LszPagination
    },
    data: data,
    props: ['caption'],
    methods: {
      hide: function () {
        this.visible = false;
      },
      show: function (uid, userName, url, filters) {
        this.uid = uid;
        this.userName = userName;
        this.getList(url, filters);
        this.visible = true;


      },
      checkClick(row) {
        let vm =  this;
        if (row) {

          let url = row.checked ? '/resourceSchoolController/addResourceSchool' : '/resourceSchoolController/deleteResourceSchool';
          let param = {
            schoolId: vm.uid,
            resourceId: row.id
          };
          vm.$http.post(url, param).then(res => {
            if (!res.data.success) {
              vm.$message({
                showClose: true,
                message: res.data.msg,
                type: 'error'
              });
              return
            }
            vm.isChange = true;
            vm.$message({
              type: 'success',
              message: '保存成功!'
            })
          })
        }
      },
      getList,
    }
  }
</script>

<style scoped>

</style>
